﻿using System;
using System.Collections.Generic;
using System.Linq;
using RNA_Libraries;

namespace RNA_Reconstruction
{
  class Program
  {
    static void Main()
    {
      HashSet<Sequence> seq;
      List<Sequence> reads;
      Sequence s = GenerateInput(out seq, out reads, .99, 100, 10, 1);

      Graph G = new Graph(reads);
      var res = G.Run(s);
      CheckResults(s, res, seq);

      Console.ReadKey();
    }

    private static void CheckResults(Sequence s, List<Vertex> res, HashSet<Sequence> seq)
    {
      var rr = res.Distinct().ToList();
      foreach (var read in rr)
      {
        Console.WriteLine(read);
        int n = s.Length;
        var b = false;
        foreach (var sequence in seq)
        {
          var ld = SequenceProcessing.LevenshteinDistance(sequence, read);
          if (sequence.ToString().Contains(read.ToString())) b = true;
          if (ld < n) n = ld;
        }
        Console.Write(string.Format("Error - {0} ", n));
        Console.Write(string.Format("Is substring - {0} ",b));
        Console.Write(string.Format("LD - {0} ", SequenceProcessing.LevenshteinDistance(s, read)));
        Console.WriteLine(string.Format("Frequency - {0}", read.Frequency));
      }
    }

    private static Sequence GenerateInput(out HashSet<Sequence> seq, out List<Sequence> reads, double solidity, int refSeqLength, int quasiNum, double splitQuatient)
    {
      Sequence s = SequenceGenerator.Generate(refSeqLength);
      //var seq = SequenceProcessing.GetSplitSeqs(s, 10);

      seq = new HashSet<Sequence>();
      reads = new List<Sequence>(1000);
      Console.WriteLine(s);
      for (int i = 0; i < quasiNum; i++)
      {
        seq.Add(MutationGeneration.Mutate(s, solidity));
      }
      if (seq.Contains(s)) seq.Remove(s);
      foreach (var se in seq)
      {
        reads.AddRange(se.Split(((int)(s.Length / splitQuatient )), 6));
        Console.WriteLine(se);
      }
      Console.WriteLine(string.Format("quasi - {0}", seq.Count));
      Console.WriteLine(string.Format("reads - {0}", reads.Count));
      return s;
    }
  }
}
 